package com.currency.mall.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.currency.mall.R;
import com.currency.mall.entity.SharesBean;
import com.currency.mall.util.Util;

import java.util.Arrays;
import java.util.List;

/**
 * Created by Administrator on 2018/12/5.
 */

public class OptionalAdapter extends BaseQuickAdapter<SharesBean.SharesInfo, BaseViewHolder> {

    private String strId[];

    public OptionalAdapter(@Nullable List<SharesBean.SharesInfo> data, Context context) {
        super(R.layout.item_optional, data);
    }

    public void setCollectShareId(String[] strId){
        this.strId = strId;
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, SharesBean.SharesInfo sharesInfo) {
        helper.addOnClickListener(R.id.ll_collect);
        helper.setText(R.id.tv_optional_name,sharesInfo.getName());
        helper.setText(R.id.tv_optional_code,sharesInfo.getCode());
        TextView currentPrice = helper.getView(R.id.tv_optional_price);
        TextView optionalPercent = helper.getView(R.id.tv_optional_percent);
        currentPrice.setText(sharesInfo.getCurrentPrice());
        helper.setText(R.id.tv_optional_percent,sharesInfo.getUpsDownsRate()+"%");
        if(sharesInfo.getUpsDownsRate() >= 0){
            optionalPercent.setBackgroundResource(R.drawable.rise_bg);
            currentPrice.setTextColor(Color.parseColor("#E51C23"));
        }else{
            optionalPercent.setBackgroundResource(R.drawable.fall_bg);
            currentPrice.setTextColor(Color.parseColor("#259B24"));
        }

        ImageView tvCollection = helper.getView(R.id.iv_collection);
        if(strId !=null){
            if(Util.useList(strId,sharesInfo.getId())){
                tvCollection.setBackgroundResource(R.drawable.collection_select);
            }else{
                tvCollection.setBackgroundResource(R.drawable.collection);
            }
        }

    }



}
